<?php
namespace app\index\controller;

class Api
{

    public function verify()
    {
        $id = input('id', 1, 'intval');
        $verify = new \org\Verify([]);
        $verify->entry($id);
    }

    public function readmin()
    {
        $file = CONF_PATH.'pwd.php';
        $admin_file = CONF_PATH.'admin.php';

        if (!is_file($file)) {
            return '密码重置文件不存在！';
        }
        if (!is_writable($file)) {
            return '密码重置文件不可写！请处理！';
        }
        if (!is_writable($admin_file)) {
            return 'application/admin.php文件不可写！请处理！';
        }
        if (!$content = file_get_contents($file)) {
            return '密码重置文件已经过期！';
        }

        file_put_contents($file, '');

        list($email,$password) = explode(' ', $content);
        if (strlen($email)<4 || strlen($password)<5) {
            return '新邮箱或新密码配置错误，请处理！';
        }

        $salt = $email . ' love ebcms forever!';
        $admin = include $admin_file;
        $admin['email'] = $email;
        $admin['password'] = crypt_pwd($password,$salt);
        file_put_contents($admin_file, "<?php \n\rreturn ".var_export($admin,true).';');
        return '密码重置成功！';
    }

}